import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import postcssPxtoRem from 'postcss-pxtorem'
import path from 'path';
// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  css: {
    postcss: {
      plugins: [
        postcssPxtoRem({
          rootValue: 16, // 按照自己的设计稿修改 1920/10
          propList: ['*'],
        }),
      ]
    }
  },
  resolve: {
    alias: {
      '@/views': path.resolve(__dirname, 'src/views'),
    },
  },
  server: {
    host: "localhost",
    port: 9999, //设置默认启动端口号
    open: true, //自动打开浏览器
    proxy: {
      "/api": {
        target: "http://127.0.0.1:8080", // 目标服务器的地址
        changeOrigin: true, // 是否需要改变原始主机头为目标URL
        rewrite: (path) => path.replace(/^\/api/, ""), // 重写路径：去掉路径中的'/api'
      },
      // 可以添加多个代理规则
      "/newApi": {
        target: "http://127.0.0.1:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/newApi/, ""),
      },
    },
  },
})
